<?php declare(strict_types=1);

namespace App\Services\Income;

use App\Models\CommonConfigs;
use App\Services\ElectronicSignature\Exception\ElSignException;
use App\Services\ElectronicSignature\Strategy\EasypayElectronicSignatureHandler;
use App\Services\ElectronicSignature\Strategy\ElectronicSignatureInterface;
use App\Services\ElectronicSignature\Strategy\GtxyElectronicSignatureHandler;
use App\Services\Income\Strategy\GtxyIncomeHandler;
use Illuminate\Http\Request;

class Bootstrap
{
    public static function run(Request $request): IncomeInterface
    {
        $api = $request->post("api", "easypay");
        switch ($api) {
            case "gtxy":
                $handler = new GtxyIncomeHandler();
                break;
            default:
                throw new \Exception("API不支持");
        }
        return $handler;
    }


    public static function handle(string $api = "gtxy"): IncomeInterface
    {
        switch ($api) {
            case "gtxy":
                $handler = new GtxyIncomeHandler();
                break;
            default:
                throw new \Exception("API不支持");
        }
        return $handler;
    }


    public static function getApplyType(string $applyType): string
    {
        switch ($applyType) {
            case "1":
                //个人开户申请
                $type = "person_company";
                break;
            case "2":
                //企业开户
                $type = "company";
                break;
            case "3":
                $type = "person";
                break;
            default:
                throw new ElSignException("签名类型异常");
        }
        return $type;
    }

    public static function getConfig(): array
    {
        $config = CommonConfigs::query()->where("config_id", "1234")->first();
        if (empty($config)) {
            throw  new \Exception("系统配置参数不存在");
        }
        $config = [
            "agetId" => $config->platform_id,
            "public_key" => $config->public_key
        ];
        return $config;
    }

}